package own;

import java.rmi.RemoteException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

import javax.xml.rpc.ServiceException;

import de.msiggi.Sportsdata.Webservices.Matchdata;
import de.msiggi.Sportsdata.Webservices.SportsdataLocator;
import de.msiggi.Sportsdata.Webservices.SportsdataSoap;

public class Soccerclient {

	private String teString = "testString";
	private List<String> gameDays;

	/**
	 * @param args
	 */
	public void fillGameDays(String team) {
		boolean mockup = true;
		List<String> lines = new ArrayList<String>();
		if (mockup) {
			lines.add("TEAM: \" " +  team);
			lines.add("TEAM2: \" " + team);
		} else {
			try {
				SportsdataSoap data = new SportsdataLocator()
						.getSportsdataSoap();
				Matchdata[] match = data.getMatchdataByLeagueSaison("bl1",
						"2012");
				DateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");
				for (Matchdata matchdata : match) {
					if (matchdata.getNameTeam1().equals(team)
							|| matchdata.getNameTeam2().equals(team)) {
						lines.add(formatter.format(matchdata.getMatchDateTime()
								.getTime())
								+ " : "
								+ matchdata.getNameTeam1()
								+ " - "
								+ matchdata.getNameTeam2()
								+ "\t"
								+ (matchdata.isMatchIsFinished() ? matchdata
										.getPointsTeam1()
										+ ":"
										+ matchdata.getPointsTeam2() : "-"));
					}
				}
			} catch (ServiceException e) {
				e.printStackTrace();
			} catch (RemoteException e) {
				e.printStackTrace();
			}
		}
		gameDays = lines;
	}

	public String getDortmund() {
		StringBuffer sb = new StringBuffer();
		try {
			SportsdataSoap data = new SportsdataLocator().getSportsdataSoap();
			Matchdata[] match = data.getMatchdataByLeagueSaison("bl1", "2012");
			DateFormat formatter = new SimpleDateFormat("dd.MM.yyyy");
			for (Matchdata matchdata : match) {
				if (matchdata.getNameTeam1().equals("Borussia Dortmund")
						|| matchdata.getNameTeam2().equals("Borussia Dortmund")) {
					sb.append(formatter.format(matchdata.getMatchDateTime()
							.getTime())
							+ " : "
							+ matchdata.getNameTeam1()
							+ " - "
							+ matchdata.getNameTeam2()
							+ "\t"
							+ (matchdata.isMatchIsFinished() ? matchdata
									.getPointsTeam1()
									+ ":"
									+ matchdata.getPointsTeam2() : "-"));
				}
			}
		} catch (ServiceException e) {
			e.printStackTrace();
		} catch (RemoteException e) {
			e.printStackTrace();
		}
		return sb.toString();

	}

	public String getTeString() {
		return teString;
	}

	public void setTeString(String teString) {
		this.teString = teString;
	}

	public List<String> getGameDays() {
		return gameDays;
	}

	public void setGameDays(List<String> gameDays) {
		this.gameDays = gameDays;
	}

}
